home *** CD-ROM | disk | FTP | other *** search
- package sun.awt;
-
- import java.awt.Toolkit;
- import java.awt.event.InvocationEvent;
- import java.beans.PropertyChangeListener;
- import java.beans.PropertyChangeSupport;
- import java.security.AccessController;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Hashtable;
- import java.util.Set;
-
- public final class AppContext {
- public static final Object EVENT_QUEUE_KEY = new StringBuffer("EventQueue");
- private static Hashtable threadGroup2appContext = null;
- private static AppContext mainAppContext = null;
- private final HashMap table = new HashMap();
- private final ThreadGroup threadGroup;
- private PropertyChangeSupport changeSupport = null;
- public static final String DISPOSED_PROPERTY_NAME = "disposed";
- public static final String GUI_DISPOSED = "guidisposed";
- private boolean isDisposed = false;
- private static int numAppContexts;
- private final ClassLoader contextClassLoader;
- private static MostRecentThreadAppContext mostRecentThreadAppContext;
- private long DISPOSAL_TIMEOUT = 5000L;
- private long THREAD_INTERRUPT_TIMEOUT = 1000L;
- private MostRecentKeyValue mostRecentKeyValue = null;
- private MostRecentKeyValue shadowMostRecentKeyValue = null;
-
- public static Set getAppContexts() {
- return threadGroup2appContext == null ? new HashSet() : new HashSet(((Hashtable)threadGroup2appContext.clone()).values());
- }
-
- public boolean isDisposed() {
- return this.isDisposed;
- }
-
- AppContext(ThreadGroup var1) {
- ++numAppContexts;
- if (threadGroup2appContext == null) {
- threadGroup2appContext = new Hashtable(2, 0.2F);
- }
-
- this.threadGroup = var1;
- threadGroup2appContext.put(var1, this);
- this.contextClassLoader = (ClassLoader)AccessController.doPrivileged(new 2(this));
- }
-
- public static final AppContext getAppContext() {
- if (numAppContexts == 1) {
- return mainAppContext;
- } else {
- Thread var0 = Thread.currentThread();
- AppContext var1 = null;
- MostRecentThreadAppContext var2 = mostRecentThreadAppContext;
- if (var2 != null && var2.thread == var0) {
- var1 = var2.appContext;
- } else {
- var1 = (AppContext)AccessController.doPrivileged(new 3(var0));
- }
-
- if (var1 == mainAppContext) {
- SecurityManager var3 = System.getSecurityManager();
- if (var3 != null && var3 instanceof AWTSecurityManager) {
- AWTSecurityManager var4 = (AWTSecurityManager)var3;
- AppContext var5 = var4.getAppContext();
- if (var5 != null) {
- var1 = var5;
- }
- }
- }
-
- return var1;
- }
- }
-
- public void dispose() throws IllegalThreadStateException {
- if (this.threadGroup.parentOf(Thread.currentThread().getThreadGroup())) {
- throw new IllegalThreadStateException("Current Thread is contained within AppContext to be disposed.");
- } else {
- synchronized(this) {
- if (this.isDisposed) {
- return;
- }
-
- this.isDisposed = true;
- }
-
- PropertyChangeSupport var1 = this.changeSupport;
- if (var1 != null) {
- var1.firePropertyChange("disposed", false, true);
- }
-
- Object var2 = new Object();
- 4 var3 = new 4(this, var1, var2);
- synchronized(var2) {
- SunToolkit.postEvent(this, new InvocationEvent(Toolkit.getDefaultToolkit(), var3));
-
- try {
- var2.wait(this.DISPOSAL_TIMEOUT);
- } catch (InterruptedException var18) {
- }
- }
-
- 5 var21 = new 5(this, var2);
- synchronized(var2) {
- SunToolkit.postEvent(this, new InvocationEvent(Toolkit.getDefaultToolkit(), var21));
-
- try {
- var2.wait(this.DISPOSAL_TIMEOUT);
- } catch (InterruptedException var16) {
- }
- }
-
- this.threadGroup.interrupt();
- long var4 = System.currentTimeMillis();
- long var6 = var4 + this.THREAD_INTERRUPT_TIMEOUT;
-
- while(this.threadGroup.activeCount() > 0 && System.currentTimeMillis() < var6) {
- try {
- Thread.sleep(10L);
- } catch (InterruptedException var15) {
- }
- }
-
- this.threadGroup.stop();
- var4 = System.currentTimeMillis();
- var6 = var4 + this.THREAD_INTERRUPT_TIMEOUT;
-
- while(this.threadGroup.activeCount() > 0 && System.currentTimeMillis() < var6) {
- try {
- Thread.sleep(10L);
- } catch (InterruptedException var14) {
- }
- }
-
- int var8 = this.threadGroup.activeGroupCount();
- if (var8 > 0) {
- ThreadGroup[] var9 = new ThreadGroup[var8];
- var8 = this.threadGroup.enumerate(var9);
-
- for(int var10 = 0; var10 < var8; ++var10) {
- threadGroup2appContext.remove(var9[var10]);
- }
- }
-
- threadGroup2appContext.remove(this.threadGroup);
- MostRecentThreadAppContext var25 = mostRecentThreadAppContext;
- if (var25 != null && var25.appContext == this) {
- mostRecentThreadAppContext = null;
- }
-
- try {
- this.threadGroup.destroy();
- } catch (IllegalThreadStateException var13) {
- }
-
- synchronized(this.table) {
- this.table.clear();
- }
-
- --numAppContexts;
- this.mostRecentKeyValue = null;
- }
- }
-
- static void stopEventDispatchThreads() {
- for(AppContext var1 : getAppContexts()) {
- if (!var1.isDisposed()) {
- PostShutdownEventRunnable var2 = new PostShutdownEventRunnable(var1);
- if (var1 != getAppContext()) {
- CreateThreadAction var3 = new CreateThreadAction(var1, var2);
- Thread var4 = (Thread)AccessController.doPrivileged(var3);
- var4.start();
- } else {
- var2.run();
- }
- }
- }
-
- }
-
- public Object get(Object var1) {
- synchronized(this.table) {
- MostRecentKeyValue var3 = this.mostRecentKeyValue;
- if (var3 != null && var3.key == var1) {
- return var3.value;
- } else {
- Object var4 = this.table.get(var1);
- if (this.mostRecentKeyValue == null) {
- this.mostRecentKeyValue = new MostRecentKeyValue(var1, var4);
- this.shadowMostRecentKeyValue = new MostRecentKeyValue(var1, var4);
- } else {
- MostRecentKeyValue var5 = this.mostRecentKeyValue;
- this.shadowMostRecentKeyValue.setPair(var1, var4);
- this.mostRecentKeyValue = this.shadowMostRecentKeyValue;
- this.shadowMostRecentKeyValue = var5;
- }
-
- return var4;
- }
- }
- }
-
- public Object put(Object var1, Object var2) {
- synchronized(this.table) {
- MostRecentKeyValue var4 = this.mostRecentKeyValue;
- if (var4 != null && var4.key == var1) {
- var4.value = var2;
- }
-
- return this.table.put(var1, var2);
- }
- }
-
- public Object remove(Object var1) {
- synchronized(this.table) {
- MostRecentKeyValue var3 = this.mostRecentKeyValue;
- if (var3 != null && var3.key == var1) {
- var3.value = null;
- }
-
- return this.table.remove(var1);
- }
- }
-
- public ThreadGroup getThreadGroup() {
- return this.threadGroup;
- }
-
- public ClassLoader getContextClassLoader() {
- return this.contextClassLoader;
- }
-
- public String toString() {
- return this.getClass().getName() + "[threadGroup=" + this.threadGroup.getName() + "]";
- }
-
- public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
- return this.changeSupport == null ? new PropertyChangeListener[0] : this.changeSupport.getPropertyChangeListeners();
- }
-
- public synchronized void addPropertyChangeListener(String var1, PropertyChangeListener var2) {
- if (var2 != null) {
- if (this.changeSupport == null) {
- this.changeSupport = new PropertyChangeSupport(this);
- }
-
- this.changeSupport.addPropertyChangeListener(var1, var2);
- }
- }
-
- public synchronized void removePropertyChangeListener(String var1, PropertyChangeListener var2) {
- if (var2 != null && this.changeSupport != null) {
- this.changeSupport.removePropertyChangeListener(var1, var2);
- }
- }
-
- public synchronized PropertyChangeListener[] getPropertyChangeListeners(String var1) {
- return this.changeSupport == null ? new PropertyChangeListener[0] : this.changeSupport.getPropertyChangeListeners(var1);
- }
-
- // $FF: synthetic method
- static AppContext access$002(AppContext var0) {
- mainAppContext = var0;
- return var0;
- }
-
- // $FF: synthetic method
- static int access$102(int var0) {
- numAppContexts = var0;
- return var0;
- }
-
- // $FF: synthetic method
- static AppContext access$000() {
- return mainAppContext;
- }
-
- // $FF: synthetic method
- static Hashtable access$200() {
- return threadGroup2appContext;
- }
-
- // $FF: synthetic method
- static MostRecentThreadAppContext access$302(MostRecentThreadAppContext var0) {
- mostRecentThreadAppContext = var0;
- return var0;
- }
-
- static {
- AccessController.doPrivileged(new 1());
- mostRecentThreadAppContext = null;
- }
- }
-